package com.xxx.video.channel.adapters;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xxx.video.R;
import com.xxx.video.channel.beans.ChanelHomeListBean;
import com.xxx.video.channel.config.ChannelFragmentItemClickType;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;

import java.util.List;

import butterknife.BindView;

public class HotChannelAdapter extends BaseRecycleViewAdapter<ChanelHomeListBean.HotListBean, HotChannelAdapter.MyHolder> {
    private List<ChanelHomeListBean.HotListBean> hotList;

    public HotChannelAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_hot_channel;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public void setListData(List<ChanelHomeListBean.HotListBean> hotList) {
        this.hotList = hotList;
        notifyDataSetChanged();
    }

    class MyHolder extends BaseViewHolder {
        @BindView(R.id.tv_item_hot_channel_title)
        TextView tvItemHotChannelTitle;
        @BindView(R.id.rcv_item_hot_channel_list)
        RecyclerView rcvItemHotChannelList;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            rcvItemHotChannelList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            HotChannelListAdapter hotChannelListAdapter = new HotChannelListAdapter(context);
            rcvItemHotChannelList.setAdapter(hotChannelListAdapter);
            hotChannelListAdapter.setData(hotList);
            hotChannelListAdapter.setOnItemClickListener((OnItemClickListener<ChanelHomeListBean.HotListBean>) (hotListBean, position1, type) -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(hotListBean, 0, ChannelFragmentItemClickType.CHANNEL_FRAGMENT_ITEM_CLICK_TYPE_START_CHANNEL_LIST);
                }
            });

        }
    }
}
